/* ========================================================================= */
/* ------------------------------------------------------------------------- */
/*!		\file		prpex_double.h
  \date		june 2011
  \author		TNick

  \brief		double class


 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Please read ReadMe.txt and Licence.txt in root folder
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


*/
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
#ifndef __PRPEX_DOUBLE_INC__
#define __PRPEX_DOUBLE_INC__
//
//
//
//
/*  INCLUDES    ------------------------------------------------------------ */
#include	<limits>
#include	<QString>
#include	"prpmdl.h"
#include	"prptpl.h"

/*  INCLUDES    ============================================================ */
//
//
//
//
/*  CLASS    --------------------------------------------------------------- */

/// class representing a double
/**
*	doubles are diffrent from all other types; they are hosting subitems
*	and are the only type allowed at top level
*/
class PEX_Dbl : public PrpTpl		{

	//
	//
	//
	//
	/*  DEFINITIONS    ----------------------------------------------------- */

	/*  DEFINITIONS    ===================================================== */
	//
	//
	//
	//
	/*  DATA    ------------------------------------------------------------ */

private:

	/// this is the value of this item
	double		dbl_value;

	/// lower limit; this value is "last" legal value
	double		dbl_low;

	/// higher limit; this value is "top" legal value
	double		dbl_high;

	/// step; ammount by which value is incremented / decremented
	double		dbl_step;

	/*  DATA    ============================================================ */
	//
	//
	//
	//
	/*  FUNCTIONS    ------------------------------------------------------- */

public:

	/// constructor;
	PEX_Dbl		(
			PrpMdl*		pa_mdl,		/**< father model */
			PrpNode*	pa_fth,		/**< father item; NULL for top level */
			QString		stra_name,	/**< name of entry */
			QString		stra_descr,	/**< description of entry */
			double		init_dbl	/**< description of entry */
			) : PrpTpl(pa_mdl, pa_fth, PrpTpl::DOUBLE, stra_name, stra_descr)
		{
			dbl_value = init_dbl;
			dbl_high = std::numeric_limits<double>::max();
			dbl_low = -1*std::numeric_limits<double>::min();
			dbl_step = 1;
		}


	/// destructor;
	virtual				~PEX_Dbl	(void) {}

	/// request actual value in text form
	virtual QVariant	valAsText	(void)
		{	return QString("%1").arg(dbl_value, 0, 'G', 3); }
	/// request decoration for the value
	virtual	QVariant	valAsDecor	(void)
		{	return QVariant(); }
	/// request to change the value made by user
	virtual bool			changeVal	(QVariant new_value);
	/// create editor for this type of item
	virtual	QWidget*	editCreate	(
			QWidget *					parent,
			const QStyleOptionViewItem	&option
			);
	/// load data from item to editor
	virtual	void		editLoad	(
			QWidget *					editor
			);
	/// save data from editor to item
	virtual	void		editSave	(
			QWidget *					editor
			);
	//	/// update geometry for the editor
	//	virtual	void		editResize	(
	//		QWidget *					editor,
	//		const QStyleOptionViewItem	&option
	//		);







	/*
Argument a is formatted according to the
specified format and precision.
See http://doc.qt.nokia.com/latest/qstring.html#argument-formats
 for details.
fieldWidth specifies the minimum amount of space that
a is padded to and filled with the character fillChar.
A positive value produces right-aligned text;
a negative value produces left-aligned text.

 double d = 12.34;
 QString str = QString("delta: %1").arg(d, 0, 'E', 3);
 // str == "delta: 1.234E+01"

The '%' can be followed by an 'L',
in which case the sequence is replaced with a
localized representation of a. The conversion uses the default locale,
set by QLocale::setDefaultLocale(). If no default
locale was specified, the "C" locale is used.

If fillChar is '0' (the number 0, ASCII 48), this function
will use the locale's zero to pad.
For negative numbers, the zero padding will probably appear before the minus sign.
*/



	inline double		value		(void)
		{ return dbl_value; }
	/// sets the name of this entry
	inline void			setValue	(double dbl_new_value)
		{ dbl_value = dbl_new_value; }

	/// tell what is the lower limit
	inline double		lowLimit	(void)
		{ return dbl_low; }
	/// set the lower limit
	inline void			setLowLimit	(double dbl_new_low)
		{ dbl_low = dbl_new_low; }


	/// tell what is the higher limit
	inline double		highLimit	(void)
		{ return dbl_high; }
	/// set the higher limit
	inline void			sethighLimit(double dbl_new_high)
		{ dbl_high = dbl_new_high; }

	/// set both limits in one go
	inline void			setLimits	(
			double dbl_new_low, double dbl_new_high)
		{ dbl_low = dbl_new_low;
			dbl_high = dbl_new_high; }


	/// tell what is the step
	inline double		step	(void)
		{ return dbl_step; }
	/// set the step
	inline void			setStep	(double dbl_new_step)
		{ dbl_step = dbl_new_step; }


	/*  FUNCTIONS    ======================================================= */
	//
	//
	//
	//

};	/*	class PEX_Dbl	*/

/*  CLASS    =============================================================== */
//
//
//
//
#endif // __PRPEX_DOUBLE_INC__
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
